/**********************************************************************
 Copyright (C) 2011 Jaakko Vuori

 This file is part of ShredMate.
 For more information, see <http://code.google.com/p/shredmate/>

 ShredMate is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 ShredMate is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ShredMate.  If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/

#include <QtCore/QCoreApplication>
#include <QThread>

#include "mp3pcmbuffer.h"
#include "pcmgenerator.h"
#include "shredmateengine.h"
#include "marker.h"
#include "range.h"

#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString fileName = argv[1];
    qDebug() << "Decoding" << fileName;
    MP3PCMBuffer buffer(fileName);
    buffer.open();
    qDebug() << "done.";

    Marker begin(0, "Begin");
    Marker middle(buffer.length() / 2, "Middle");
    Marker middlePlusSomeMore(buffer.length() / 2 + 500000, "Middle plus some more");
    Marker end(buffer.length() - 1, "End");

    QList<Marker> markers;
    markers << begin
            << middle
            << middlePlusSomeMore
            << end;

    QList<Range> ranges;
    ranges << Range(begin, middle, "First half")
           << Range(middle, end, "Last half")
           << Range(middle, middlePlusSomeMore, "Short snippet starting from the middle of the song");

    PCMGenerator pcmGenerator;
    ShredmateEngine engine(&pcmGenerator);
    engine.setPCMBuffer(&buffer);

    engine.setMarkers(markers);
    engine.setRanges(ranges);
    engine.setActiveRange(2);

    engine.setLooping(true);
    engine.play();

    return a.exec();
}
